// 返回格式化后的日期
function dateFormat(date, format = "YYYY-MM-DD HH:mm") {
    const config = {
        YYYY: date.getFullYear(),
        MM: date.getMonth() + 1 < 10 ?
            `0${date.getMonth() + 1}` : date.getMonth() + 1,
        DD: date.getDate() < 10 ? `0${date.getDate()}` : date.getDate(),
        HH: date.getHours() < 10 ? `0${date.getHours()}` : date.getHours(),
        mm: date.getMinutes() < 10 ? `0${date.getMinutes()}` : date.getMinutes(),
        ss: date.getSeconds() < 10 ? `0${date.getSeconds()}` : date.getSeconds(),
    };
    for (let key in config) {
        format = format.replace(key, config[key]);
    }
    return format;
}

module.exports = dateFormat